<template>
<div>
    <form @submit.prevent>
        <input v-model="name" placeholder="请输入你的昵称" />
        <button @click="submit">登录</button>
    </form>
</div>
</template>
<script lang="ts">
import {
    Component
} from "vue-property-decorator";
import {
    BaseVue
} from "../base-vue";

@Component < AppComponent > ({
    components: {},
    metaInfo() {
        return {
            title: "登录"
        };
    }
})
export default class AppComponent extends BaseVue {
    public name = "";
    public async submit() {
        if (!this.name) {
            return alert("请输入昵称");
        }
        const res = await this.request.post("/api/signin", {
            name: this.name
        });
        if (res.success) {
            this.signin(this.name);
            this.$router.back();
            return;
        }
        alert("登录失败");
    }
}
</script>
